<?php


require_once(DIR_LIB."VsGui".DIR_SEP."vssmartywidget.php");
require_once(DIR_LIB."VsGui".DIR_SEP."vsseo.php");

class VsSmartyPage extends VsSmartyWidget {

	private $_tplHtmlHeader = '';

	protected $_pageTitle = 'Untitled';
	protected $_pageCharset = 'utf8';

	protected $_metaTags = array();

	protected $_bodyAtributes = array();

	protected $_jsFiles = array();
	protected $_cssFiles = array();

	protected $jsCode = '';
	protected $_cssCode = '';

	protected $_onLoad = '';
	protected $_onResize = '';

	protected $_AdminToolbar = NULL;
	protected $_Seo = NULL;

	protected $_widgets = array();

	protected static $_Instance = NULL;

	static function Instance() {
		if(!self::$_Instance)
			self::$_Instance = new VsSmartyPage();

		return self::$_Instance;
	}
	//===========================================================================

	protected function __construct() {
		parent::__construct();

		$this->assign('hostDir', isset($GLOBALS['hostDir']) ? $GLOBALS['hostDir'] : '');

		$this->_tplHtmlHeader = dirname(__FILE__).DIR_SEP."html".DIR_SEP."header_xhtml_strict.html";

		$this->_Seo = new VsSeo($this);
	}
	//===========================================================================

	function __destruct() {
		$html = "</body>\n</html>";

		echo $html;
	}
	//============================================================================

	function setTitle($title) { $this->_pageTitle = $title; }
	function title() { return $this->_pageTitle; }
	

	function jsFiles() { return $this->_jsFiles; }
	function cssFiles() { return $this->_cssFiles; }

	function addJsFile($jsFile) { array_push($this->_jsFiles, $jsFile); }
	function addCssFile($cssFile) { array_push($this->_cssFiles, $cssFile); }
	// For Convenience
	function addScript($file) { $this->addJsFile($file); }
	function addStyle($file) { $this->addCssFile($file); }
	function scripts() { return $this->_jsFiles; }
	function styles() { return $this->_cssFiles; }
	
	
	function addJsCode($jsCode) { $this->_jsCode .= $jsCode; }
	function addCssCode($cssCode) { $this->_cssCode .= $cssCode; }

	function addBodyOnLoad($onLoad) { $this->_onLoad .= $onLoad; }
	function addBodyOnResize($onResize) { $this->_onResize .= $onResize; }

	function addSeoKey($key) { $this->_Seo->addKey($key); }
	function addSeoKeys($keys) { $this->_Seo->addKeys($keys); }

	function setAdminToolbar($toolbar) { $this->_AdminToolbar = $toolbar; }
	
	function addWidget($widget) { array_push($this->_widgets, $widget); }
	function addTemplate($template) { $this->addGuiComponent($template); }
	//===============================================================================

	function show() {
		$html = '';

		$this->assign('siteTitle', VsApplication::Instance()->title());

		$this->assign('pageTitle', $this->_pageTitle);
		$this->assign('pageCharset', $this->_pageCharset);

		$this->assign('metaTags', $this->_metaTags);

		$this->assign('jsFiles', $this->_jsFiles);
		//echo "JsFiles Count: ".sizeof($this->_jsFiles);
		$this->assign('cssFiles', $this->_cssFiles);

		//$this->repairDelimiterConflicts();
		$this->assign('jsCode', $this->_jsCode);
		$this->assign('cssCode', $this->_cssCode);

		$this->assign('onLoad', $this->_onLoad);
		$this->assign('onResize', $this->_onResize);

		$html .= $this->fetch($this->_tplHtmlHeader);

		if($this->_AdminToolbar)
			$html .= $this->_AdminToolbar->show();

		if($this->_Seo)
			$html .= $this->_Seo->show();

		foreach($this->_widgets as &$w) {
			$html .= $w->show();

			//echo "EHO";
		}

		return $html;
	}
	//==============================================================================

	function html() { return $this->show(); }

	function bodyContent() {
		$html = '';

		foreach($this->_widgets as &$w) {
			$html .= $w->show();
		}

		return $html;
	}
	//================================================================================

	
};

?>
